package com.Practice;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.Serdes;
import org.apache.kafka.streams.StreamsBuilder;
import org.apache.kafka.streams.StreamsConfig;
import org.apache.kafka.streams.kstream.KStream;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

public class UserLogin {
    public static void main(String[] args) throws IOException {
        // 1. 准备生产者的配置对象
        Properties props = new Properties();
        props.put("bootstrap.servers", "niit01:9092");
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        Producer<String, String> producer = new KafkaProducer<>(props);
        BufferedReader br = new BufferedReader(new FileReader("C:/Users/86132/Desktop/user_login.csv"));
        String line;
        while ((line = br.readLine()) != null) {
            String[] parts = line.split(",");
            if (parts.length >= 3) {
                String row = parts[0].trim();
                String userId = parts[1].trim();
                String timestamp = parts[2].trim();
                String kafkaMessage = row + "," + userId + "," + timestamp;
                ProducerRecord<String, String> record = new ProducerRecord<>("test_login3", null, kafkaMessage);
                producer.send(record);
            }
        }
        br.close();
        producer.close();
    }
}
